package com.ymatou.iapi.sellerquery.testcase;

import java.util.ArrayList;
import java.util.Map;

import org.apache.log4j.spi.ErrorCode;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.Gson;
import com.ymatou.auth.parameter.SecurityQuestion;
import com.ymatou.iapi.sellerquery.parameter.GetOrderCreditListBean;
import com.ymatou.iapi.sellerquery.parameter.resp.CreditInfoListResp;
import com.ymatou.iapi.sellerquery.parameter.resp.OrderInfoListResp;
import com.ymatou.iapi.sellerquery.service.GetOrderCreditListCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 获取维权订单列表 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetOrderCreditList {

	private static GetOrderCreditListBean goclbean;
	private static GetOrderCreditListCall goclcall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取维权订单列表");
	}

	@Before
	public void caseUp() {

		goclbean = new GetOrderCreditListBean();
		goclcall = new GetOrderCreditListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(goclcall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	private void verifyDB() {
		int OrderId = 100004924;
		Logger.comment("验证表ymt_CreditDetail");
		Map database = new DefaultWapper().selectCreditDetailByOrderId(OrderId).get(0);		
		ArrayList<CreditInfoListResp> list = goclcall.getResult();
		for (CreditInfoListResp returnMessage : list) {	
			Logger.verifyEquals( database.get("iCreditDetailId").toString(), 
					returnMessage.getCreditDetailId().toString(), "验证维权订单表creditDetailId");
			Logger.verifyEquals( database.get("iUserId"), 
					returnMessage.getUserId(), "验证维权订单表userId");
			Logger.verifyEquals( database.get("sTargetId"), 
					returnMessage.getTargetId().toString(), "验证维权订单表targetId");
			Logger.verifyEquals(Double.valueOf(database.get("fPoint").toString()), 
					Double.valueOf(returnMessage.getServiceRange()), "验证维权订单表serviceRange");
			Logger.verifyEquals(database.get("sDescription"), 
					returnMessage.getDescription(), "验证维权订单表description");
			Logger.verifyEquals(database.get("iSort"), 
					returnMessage.getSort(), "验证维权订单表sort");				
			Logger.verifyEquals(database.get("iType"), 
					returnMessage.gettype(), "验证维权订单表type");				
			Logger.verifyEquals(database.get("sIP"), 
					returnMessage.getIp().toString(), "验证维权订单表ip");				
			DataUtil.verifyDateEquals(database.get("dAddTime"),
					returnMessage.getAddTime(),"验证维权订单表addTime");	
			DataUtil.verifyDateEquals(database.get("dUpdateTime"),
					returnMessage.getUpdateTime(),"验证维权订单表updateTime");					
			Logger.verifyEquals(database.get("iAction"), 
					returnMessage.getAction(), "验证维权订单表action");
			Logger.verifyEquals(database.get("iTargetUserId"), 
					returnMessage.getTargetUserId(), "验证维权订单表targetUserId");
			Logger.verifyEquals(database.get("fPoint2"), 
					returnMessage.getServiceRange(), "验证维权订单表serviceRange");
			Logger.verifyEquals(database.get("iPoint3"), 
					returnMessage.getPraiseRange(), "验证维权订单表praiseRange");
			Logger.verifyEquals(database.get("sSellerReply"), 
					returnMessage.getSellerReply(), "验证维权订单表sellerReply");
			Logger.verifyEquals(database.get("dSellerReplyUpdateTime"), 
					returnMessage.getSellerReplyUpdateTime(), "验证维权订单表sellerReplyUpdateTime");
			Logger.verifyEquals(database.get("bFromPurchaseAgent"), 
					returnMessage.getFromPurchaseAgent(), "验证维权订单表fromPurchaseAgent");
			}
		}
	
	

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetOrderCreditList_001() {
		Logger.start(true,"获取维权订单列表成功");
		try {
			int OrderId = 100004924;
			goclbean.setOrderId(OrderId);
			String s=FormatUtil.beanToHttpString(goclbean, true, false);
			goclcall.setData(s);
			goclcall.callService();
			Logger.verifyEquals(ECode.SUCCESS, goclcall.getCode(), "验证Code");
			
			//数据库验证
			verifyDB();
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetOrderCreditList_002() {
		Logger.start(true,"订单号为空，获取维权订单列表失败");
		try {
		//	goclbean.setOrderId(100004924);
			String s=FormatUtil.beanToHttpString(goclbean, true, false);
			goclcall.setData(goclbean);
			goclcall.callService();
			Logger.verifyEquals(ECode.FAILED400, goclcall.getCode(), "验证code");
			Logger.verifyEquals(ECode.BCODE8, goclcall.getBCode(), "验证bcode");
			Logger.verifyEquals("orderId:订单号未提供", goclcall.getMsg(), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetOrderCreditList_003() {
		Logger.start(true,"订单号不存在，获取维权订单列表为空,成功");
		try {
			goclbean.setOrderId(123456789);
			String s=FormatUtil.beanToHttpString(goclbean, true, false);
			goclcall.setData(s);
			goclcall.callService();
			Logger.verifyEquals(ECode.SUCCESS, goclcall.getCode(), "验证code");
	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}